package com.itheima.common.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 封装返回结果
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable{
    private boolean flag;//执行结果，true为执行成功 false为执行失败
    private String message;//返回结果信息，主要用于页面提示信息
    private T data;//返回数据

    /**
     *  增删改 成功响应
     */
    public static <T> Result<T> success(String msg){
        Result<T> result = new Result<T>();
        result.flag = true;
        result.message = msg;
        return result;
    }
    /**
     *查询 成功响应
     */
    public static <T> Result<T> success(T data,String msg){
        Result<T> result = new Result<T>();
        result.flag = true;
        result.message=msg;
        result.data = data;
        return result;
    }
    /**
     * 失败响应
     */
    public static <T> Result<T> error(String msg){
        Result<T> result = new Result<T>();
        result.flag = false;
        result.message = msg;
        return result;
    }
}
